﻿Imports System.Net.Sockets
Imports System.Net

Public Class Server

    Private ip As String
    Private port As String

    Private conn As TcpListener

    Private state As status = status.STOPPED

    Public Sub New(ByVal ip As String, ByVal port As String)
        Me.ip = ip
        Me.port = port
    End Sub

    Private Enum status
        RUNNING
        STOPPED
        PAUSED
    End Enum

    Public Sub startServer()
        If Tools.IpTools.VerifyIp(Me.ip) AndAlso state = status.STOPPED Then

            conn = New TcpListener(IPAddress.Parse(ip), port)
            conn.Start()

            Console.WriteLine("Il Server Si e' avviato correttamente")
            Me.state = status.RUNNING

        End If
    End Sub

    Public Sub StopServer()

        If Me.state = status.RUNNING Then

            conn.Stop()
            Me.state = status.STOPPED

        End If

    End Sub

End Class
